package com.hcy.asyncfiledownload.ordermodule.service.impl;

import com.alibaba.fastjson.JSON;
import com.hcy.asyncfiledownload.common.dto.OrderExportDto;
import com.hcy.asyncfiledownload.common.entry.ExportRecord;
import com.hcy.asyncfiledownload.common.enums.ExportStatus;
import com.hcy.asyncfiledownload.datamodule.annotion.ProviderType;
import com.hcy.asyncfiledownload.mockdatabase.MockData;
import com.hcy.asyncfiledownload.ordermodule.mq.MockMqProvider;
import com.hcy.asyncfiledownload.ordermodule.service.IOrderService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author huchenying
 * @Date 2022/9/6 11:11
 * @Description order服务
 */
@Service
@Log4j2
public class OrderService implements IOrderService {

    @Autowired
    MockMqProvider provider;

    public void handlerOrderExport(OrderExportDto dto) {
        log.info("handlerOrderExport start param -> {}", dto);
        // 生成一条导出记录
        ExportRecord exportRecord = new ExportRecord();
        // 设置初始状态
        exportRecord.setStatusCode(ExportStatus.Init.getCode());
        exportRecord.setProviderType(ProviderType.OrderExport);
        // 序列化查询条件
        exportRecord.setQueryString(JSON.toJSONString(dto));
        MockData.insertExportRecord(exportRecord);
        // 发送mq
        provider.pushMessage(exportRecord);
    }
}
